﻿<!DOCTYPE>

<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=EDGE;IE=11;IE=8,chrome=1" />
    <title>排产超期分析</title>
    <link href="/InSiteWebApplication/Content/Easyui/themes/metro/easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/custom-easyui.css" rel="stylesheet" />
    <link href="/InSiteWebApplication/Content/Easyui/themes/icon.css" rel="stylesheet" />
   
</head>
<body>
    <div style="margin:3px 0 0 3px" >
         <div class="" style="margin-bottom: 5px;font-size:16px;font-weight:700 ">
                            考虑分厂日历,不考虑班次,保养和占用：<span id="apsASResult" ></span>
         </div>
         <div style="margin:3px 0 0 3px" >             
                <table id="gdContainerAps" class="easyui-datagrid" style="width: 100%; height: 100px"
                        data-options="rownumbers:true,pagination:false,striped:true,checkOnSelect:true,selectOnCheck:true,singleSelect:false,pageNumber:1,pageSize:5,pageList:[5,10,20]">
                </table>
            
         </div>
    </div>
    <div style="margin:3px 0 0 3px" >
         <div class="" style="margin-bottom: 5px; font-size:16px;font-weight:700">
                            不考虑日历,班次,保养和占用：<span id="apsASResult2" ></span>
         </div>
         <div style="margin:3px 0 0 3px" >
            <table id="gdContainerAps2" class="easyui-datagrid" style="width: 100%; height: 100px"
                        data-options="rownumbers:true,pagination:false,striped:true,checkOnSelect:true,selectOnCheck:true,singleSelect:false,pageNumber:1,pageSize:5,pageList:[5,10,20]">
                </table>
         </div>
    </div>
</body>
</html>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/ReferenceJsLib.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/jquery.easyui.min.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Content/Easyui/easyui-lang-zh_CN.js" type="text/javascript"></script>
<script src="/InSiteWebApplication/Scripts/CustomPageJs/CustomCommon.js" type="text/javascript"></script>
<script type="text/javascript">
    var page = {
        parentID: '', //父窗体div
        popupData: '',
        returnData: null, //返回的消息
        rootPath: getRootPath(), //网站根路径
        ajaxUrl: getRootPath() + "/Ashx/ApsHandler/ApsLimitedCapacityHandler.ashx",
        //初始化页面
        init: function () {
            page.bind();

            page.apsAnalysis();
            page.apsAnalysis2();
        },
        //页面事件绑定
        bind: function () {
            $("#gdContainerAps").datagrid({
                onLoadSuccess: function (data) {
                    var row = data.rows[0];
                    if (row.APSTYPE == "1") {
                        if (row.ENDTIME != null && dayjs(dayjs(row.ENDTIME).format('YYYY-MM-DD')) > dayjs(dayjs(row.MFGENDDDATE).format('YYYY-MM-DD'))) {
                            $("#apsASResult").css("color", "red");
                            $("#apsASResult").text("仍然超期,建议不考虑日历试算");
                        } else {
                            $("#apsASResult").text("不超期,建议增加工序设备或增加班次");
                        }
                    } else if (row.APSTYPE == "2") {
                        if (row.STARTTIME != null && dayjs(dayjs(row.STARTTIME).format('YYYY-MM-DD')) < dayjs(dayjs(row.MFGSTARTDATE).format('YYYY-MM-DD'))) {//REALSTARTDATE
                            $("#apsASResult").css("color", "red");
                            $("#apsASResult").text("仍然超期,建议不考虑日历试算");
                        } else {
                            $("#apsASResult").text("不超期,建议增加工序设备或增加班次");
                        }
                    } else if (row.APSTYPE == "3") {
                        var isOverDue = false; //是否超期
                        if (row.ENDTIME != null && dayjs(dayjs(row.ENDTIME).format('YYYY-MM-DD')) > dayjs(dayjs(row.MFGENDDDATE).format('YYYY-MM-DD'))) {
                            $("#apsASResult").css("color", "red");
                            $("#apsASResult").text("仍然超期,建议不考虑日历试算");
                            isOverDue = true;
                        }
                        if (row.STARTTIME != null && dayjs(dayjs(row.STARTTIME).format('YYYY-MM-DD')) < dayjs(dayjs(row.MFGSTARTDATE).format('YYYY-MM-DD'))) {//REALSTARTDATE
                            $("#apsASResult").css("color", "red");
                            $("#apsASResult").text("仍然超期,建议不考虑日历试算");
                            isOverDue = true;
                        }

                        if (!isOverDue) {
                            $("#apsASResult").text("不超期,建议增加工序设备或增加班次");
                        }


                    }
                },
                columns: [[
                //                 { field: 'ck', title: '选择', checkbox: true },
                 {field: 'MFGORDERNAME', title: '订单号', width: 120 },
		         { field: 'CONTAINERNAME', title: '批次', width: 150 },
		         { field: 'PRODUCTDESC', title: '零件名称', width: 130, hidden: true },
                 { field: 'QTY', title: '在制数', width: 60 },
                 { field: 'WORKFLOWINFO', title: '工艺信息', width: 180, hidden: true },
                 { field: 'STARTTIME', title: '开始时间', width: 125, formatter: function (value, row, index) {
                     if (value != null)
                         return value.substring(0, value.lastIndexOf(":"));
                 },
                     styler: function (value, row, index) {
                         if (value != null && dayjs(dayjs(value).format('YYYY-MM-DD')) < dayjs(dayjs(row.MFGSTARTDATE).format('YYYY-MM-DD'))) {//REALSTARTDATE
                             return 'background-color:#ffee00;';
                         }
                     }
                 },
                 { field: 'ENDTIME', title: '结束时间', width: 125, formatter: function (value, row, index) {
                     if (value != null)
                         return value.substring(0, value.lastIndexOf(":"));
                 },
                     styler: function (value, row, index) {
                         if (value != null && dayjs(dayjs(value).format('YYYY-MM-DD')) > dayjs(dayjs(row.MFGENDDDATE).format('YYYY-MM-DD'))) {
                             return 'background-color:#ffee00;';
                         }
                     }
                 },
                 { field: 'APSTYPE', title: '排产策略', width: 80, formatter: function (value, row, index) {
                     switch (value) {
                         case "1":
                             return "正排";
                             break;
                         case "2":
                             return "倒排";
                             break;
                         case "3":
                             return "瓶颈排";
                             break;
                         default:
                             return "";
                             break;
                     }
                 }
                 },
		         { field: 'WORKFLOWID', title: '工艺', hidden: true },
                 { field: 'CONTAINERID', title: 'CONTAINERID', hidden: true },
                 { field: 'CONTAINERTYPE', title: '流水卡类型', hidden: true },
                 { field: 'APSPLANINFOID', title: 'APSPLANINFOID', hidden: true }

	           ]]
            });
            $("#gdContainerAps2").datagrid({
                onLoadSuccess: function (data) {
                    var row = data.rows[0];
                    if (row.APSTYPE == "1") {
                        if (row.ENDTIME != null && dayjs(dayjs(row.ENDTIME).format('YYYY-MM-DD')) > dayjs(dayjs(row.MFGENDDDATE).format('YYYY-MM-DD'))) {
                            $("#apsASResult2").css("color", "red");
                            $("#apsASResult2").text("仍然超期,建议更改订单计划");
                        } else {
                            $("#apsASResult2").text("不超期,建议假期加班、增加设备完成");
                        }
                    } else if (row.APSTYPE == "2") {
                        if (row.STARTTIME != null && dayjs(dayjs(row.STARTTIME).format('YYYY-MM-DD')) < dayjs(dayjs(row.MFGSTARTDATE).format('YYYY-MM-DD'))) {//REALSTARTDATE
                            $("#apsASResult2").css("color", "red");
                            $("#apsASResult2").text("仍然超期,建议更改订单计划");
                        } else {
                            $("#apsASResult2").text("不超期,建议假期加班、增加设备完成");
                        }
                    } else if (row.APSTYPE == "3") {
                        var isOverDue = false; //是否超期
                        if (row.ENDTIME != null && dayjs(dayjs(row.ENDTIME).format('YYYY-MM-DD')) > dayjs(dayjs(row.MFGENDDDATE).format('YYYY-MM-DD'))) {
                            $("#apsASResult2").css("color", "red");
                            $("#apsASResult2").text("仍然超期,建议更改订单计划");
                            isOverDue = true;
                        }
                        if (row.STARTTIME != null && dayjs(dayjs(row.STARTTIME).format('YYYY-MM-DD')) < dayjs(dayjs(row.MFGSTARTDATE).format('YYYY-MM-DD'))) {//REALSTARTDATE
                            $("#apsASResult2").css("color", "red");
                            $("#apsASResult2").text("仍然超期,建议更改订单计划");
                            isOverDue = true;
                        }
                        if (!isOverDue) {
                            $("#apsASResult").text("不超期,建议增加工序设备或增加班次");
                        }
                    }
                },
                columns: [[
                //                 { field: 'ck', title: '选择', checkbox: true },
                 {field: 'MFGORDERNAME', title: '订单号', width: 120 },
		         { field: 'CONTAINERNAME', title: '批次', width: 150 },
		         { field: 'PRODUCTDESC', title: '零件名称', width: 130, hidden: true },
                 { field: 'QTY', title: '在制数', width: 60 },
                 { field: 'WORKFLOWINFO', title: '工艺信息', width: 180, hidden: true },
                 { field: 'STARTTIME', title: '开始时间', width: 125, formatter: function (value, row, index) {
                     if (value != null)
                         return value.substring(0, value.lastIndexOf(":"));
                 },
                     styler: function (value, row, index) {
                         if (value != null && dayjs(dayjs(value).format('YYYY-MM-DD')) < dayjs(dayjs(row.MFGSTARTDATE).format('YYYY-MM-DD'))) {//REALSTARTDATE
                             return 'background-color:#ffee00;';
                         }
                     }
                 },
                 { field: 'ENDTIME', title: '结束时间', width: 125, formatter: function (value, row, index) {
                     if (value != null)
                         return value.substring(0, value.lastIndexOf(":"));
                 },
                     styler: function (value, row, index) {
                         if (value != null && dayjs(dayjs(value).format('YYYY-MM-DD')) > dayjs(dayjs(row.MFGENDDDATE).format('YYYY-MM-DD'))) {

                             return 'background-color:#ffee00;';
                         }
                     }
                 },
                 { field: 'APSTYPE', title: '排产策略', width: 80, formatter: function (value, row, index) {
                     switch (value) {
                         case "1":
                             return "正排";
                             break;
                         case "2":
                             return "倒排";
                             break;
                         case "3":
                             return "瓶颈排";
                             break;
                         default:
                             return "";
                             break;
                     }
                 }
                 },
		         { field: 'WORKFLOWID', title: '工艺', hidden: true },
                 { field: 'CONTAINERID', title: 'CONTAINERID', hidden: true },
                 { field: 'CONTAINERTYPE', title: '流水卡类型', hidden: true },
                 { field: 'APSPLANINFOID', title: 'APSPLANINFOID', hidden: true }

	           ]]
            });
        }
        , apsAnalysis: function () {
            var gridID = "#gdContainerAps";
            var param = {
                action: "apsLmCalculateTrial",
                noIncludeMC: "0",
                noIncludeUK: "1",
                noIncludeOP: "1",
                noIncludeSF: "1",
                containers: JSON.stringify(page.popupData)
            };
            //console.log(param);
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $(gridID).datagrid('loading');
                    $(this).attr("disabled", "disabled"); //禁用按钮
                },
                success: function (data) {
                    $(gridID).datagrid('loaded');
                    $(this).removeAttr("disabled"); //恢复按钮
                    var result = JSON.parse(data);
                    if (result.Result) {
                        var dt = result.DBTable;
                        page.popupData[0].STARTTIME = dt[0].STARTTIME;
                        page.popupData[0].ENDTIME = dt[0].ENDTIME;
                        $("#gdContainerAps").datagrid('loadData', { total: page.popupData.length, rows: page.popupData })
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $(gridID).datagrid('loaded');
                    $(this).removeAttr("disabled"); //恢复按钮
                    alert(XMLHttpRequest.responseText);
                }
            });
        }
        , apsAnalysis2: function () {
            var gridID = "#gdContainerAps2";
            var param = {
                action: "apsLmCalculateTrial",
                noIncludeMC: "1",
                noIncludeUK: "1",
                noIncludeOP: "1",
                noIncludeSF: "1",
                containers: JSON.stringify(page.popupData)
            };
            //console.log(param);
            $.ajax({
                type: "Post",
                url: page.ajaxUrl,
                data: param,
                cashe: false,
                async: true,
                beforeSend: function () {
                    $(gridID).datagrid('loading');
                    $(this).attr("disabled", "disabled"); //禁用按钮
                },
                success: function (data) {
                    $(gridID).datagrid('loaded');
                    $(this).removeAttr("disabled"); //恢复按钮
                    var result = JSON.parse(data);
                    if (result.Result) {
                        var dt = result.DBTable;
                        page.popupData[0].STARTTIME = dt[0].STARTTIME;
                        page.popupData[0].ENDTIME = dt[0].ENDTIME;
                        $(gridID).datagrid('loadData', { total: page.popupData.length, rows: page.popupData })
                    } else {
                        displayMessage(result.Message, false);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    $(gridID).datagrid('loaded');
                    $(this).removeAttr("disabled"); //恢复按钮
                    alert(XMLHttpRequest.responseText);
                }
            });
        }
    };
    $(function () {
        page.parentID = getParam("parentDiv");
        page.popupData =parent.$("#" + page.parentID).dialog('options').popupData;
        //console.log(page.popupData);
        page.init();

    });
</script>
